
#include<stdio.h>
void ShellSort(int* a, int n)
{
	int gap = n;
	while (gap > 1)
	{
		gap = gap / 2;
		for (int i = 0; i < n - gap; i++) {
		int end=i;
		int temp = a[end + gap];
		while (end >= 0) {
            if (a[end] > temp) {
			    a[end+gap] = a[end];
				end = end - gap;
		    }
			else {
				break;
			}
		}
		a[end+gap] = temp;
	    }
	}
}
int main()
{
	int a[] = { 9,8,7,6,5,4,3,2,1 };
	ShellSort(a, sizeof(a) / sizeof(int));
	for (int i = 0; i < sizeof(a)/sizeof(int); i++) {
		printf("%d ", a[i]);
	}
	return 0;
}